package test.kit.hutool.json;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.json.JSONUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.nio.charset.Charset;
import java.util.List;

@Slf4j
public class SchoolUtils {

    String FILE = "school_list.json";

    @Data
    public static class SchoolInfo {
        Integer schoolId;
        String schoolName;
    }

    @Test
    public void test() {
        // 读取数据
        String json = IoUtil.read(ResourceUtil.getStream(FILE), Charset.defaultCharset());
        List<SchoolInfo> dataLt = JSONUtil.toList(json, SchoolInfo.class);
        // 排序
        CollectionUtil.sortByProperty(dataLt, "schoolId");

        // 分批
        ListUtil.partition(dataLt, 10).forEach(e -> {
            List<Integer> ids = CollectionUtil.map(e, SchoolInfo::getSchoolId, true);
            log.info("{}", ids);
        });
    }
}
